define(['jquery','api','util','text!pages/order/points.html','Vue'],function($,api,util,tpl,Vue){
	var vm,
	   time,
	   startid,
	   hash={
	      'openamount':'期初',
	      'registaamount':'注册',
          'loginamount':'登入',
          'tradeamount':'交易',
          'orderamount':'单据',
          'outamount':'导出',
          'balanceamount':'可用积分'
	   },
	   controller = {
	   init:function(id){
	   	   if(!user.checkLogin())return;
		   api.initFooter(3);
		   api.setTitle('我的积分');	
		   if(!vm){
		     this.render();
		   }else{
		     vm.show=true;
		   }
		   this.loadPoints();
	   },
	   render:function(){
	   	  var that=this;
	   	   $('#pages').append('<div id="points"></div>');
	        vm=new Vue({
	           el:'#orderHistrory',
	           data:{
	           	  show:true,
	           	  balanceamount:false,
			      pointObj:false,
	           	  loading:true,
                  showMore:false
	           },
	           filters:{
	             getPointsType:function(v){
	                  return hash[v]?hash[v]:'';
	             }
	          },
	           methods:{
	           },
	           template:tpl
	        });
	   },
	   loadPoints:function(more){
           startid=0;
           this.load();
	   },
	   load:function(){
           var rows;
	   	   var params={id:startid,count:20};
	   	   api.points(params,function(rs){
               if(rs.retcode=='0' && typeof rs.data!='undefined'){
                    rows=rs.data;
                    vm.pointObj = rows;
                    vm.loading = false;
                    var len = rows.length;
                    startid+=len;
                    if(len>=20){
                       vm.showMore.history=true;
                    }else{
                       vm.showMore.history=false;
                    }
               }
	   	   })
	   },
	   onRouteChange:function(){
	       if(vm)vm.show=false;
	   }
	};
    return controller;
})